package com.yjhb.android.sbz.v2.mvp.presenter

import com.yjhb.android.sbz.App
import com.yjhb.android.sbz.http.HttpObserver
import com.yjhb.android.sbz.http.HttpTool
import com.yjhb.android.sbz.mvp.ConventionPresenter
import com.yjhb.android.sbz.v2.mvp.view.V2BindView


/**
 *  创建者 zx
 *  创建时间 2021/8/10 16:51
 */
class BindPresenter(v: V2BindView) : ConventionPresenter<V2BindView>(v) {

    /**
     * 认证
     *
     * @param name
     * @param idCard
     */
    fun updateIdentityInfo(name: String?, idCard: String?) {
        if (checkUnLogin()) return
        view?.onWait("努力加载中...")
        model?.let {
            HttpTool.request(model.updateIdentityInfo(App.userInfo!!.id, name, idCard), object : HttpObserver<String?>() {

                override fun onResult(data: String?) {
                    view?.onBindSuccess(1)

                }

                override fun onError(code: Int, msg: String) {
                    view?.onFailure(code, msg)

                }

            })
        }

    }

    /**
     * 绑定支付宝
     *
     * @param name
     * @param zfbAccount
     */
    fun updateZfbAccount(name: String?, zfbAccount: String?, idCard: String?) {
        if (checkUnLogin()) return
        view?.onWait("努力加载中...")
        model?.let {
            HttpTool.request(it.updateZfbAccount(App.userInfo!!.id, zfbAccount, name, idCard), object : HttpObserver<String?>() {

                override fun onError(code: Int, msg: String) {
                    view?.onFailure(code, msg)
                }
                override fun onResult(data: String?) {
                    view?.onBindSuccess(2)
                }
            })
        }

    }

}